#ifndef H_ITEMCOMBOBOX
#define H_ITEMCOMBOBOX
#include "precompiled.h"
#include "engine/utility.h"
#include "engine/engineheader.h"
namespace weo
{
    namespace ui
    {
        template<typename T>
        class ItemComboBox : public QComboBox
        {
        private:
            std::vector<const T*> m_ItemData;
            bool eventhandler(QEvent *event);
            bool event(QEvent *event);
        public:
            void clear()
            {
                m_ItemData.clear();
                QComboBox::clear();
            }
            void addItem(const T* value)
            {
                m_ItemData.push_back(value);
                QComboBox::addItem(tr(value->Name().c_str()));
            }
            const T* getCurrentItem() const
            {
                if(QComboBox::currentIndex() < 0 || m_ItemData.empty()) return NULL;
                return m_ItemData[currentIndex()];
            }
            const T* getItemAt(unsigned int index) const
            {
                if(index < 0 || m_ItemData.empty()) return NULL;
                return m_ItemData[currentIndex()];
            }
            void setCurrentItem(const T* item)
            {
                std::vector<const T*>::const_iterator it;
                for(it = m_ItemData.begin(); it!= m_ItemData.end();it++)
                {
                    const T *test = *it;
                    if(test->Id() == item->Id())
                    {
                        unsigned int index = it-m_ItemData.begin();
                        QComboBox::setCurrentIndex(index);
                        break;
                    }
                }
                if(it == m_ItemData.end())
                {
                    QComboBox::setCurrentIndex(findText(tr("None")));
                }
            }

        };
    };
};
#endif